package com.strawcom.charmring.util;

import org.kymjs.kjframe.utils.PreferenceHelper;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 
 * @ClassName: PreferenceUtil
 * @Description:Preference工具类
 * @author liyongqiang
 * @date 2015-3-30 上午12:03:04
 * 
 */
public class PreferenceUtil {

	public static final String sp_path = "ring_sp_info";

	public static void write(Context context, String k, int v) {
		PreferenceHelper.write(context, sp_path, k, v);
	}
	
	public static void write(Context context, String k, float v) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
	            Context.MODE_PRIVATE);
        Editor editor = preference.edit();
        editor.putFloat(k, v);
        editor.commit();
	}

	public static void write(Context context, String k, boolean v) {
		PreferenceHelper.write(context, sp_path, k, v);
	}

	public static void write(Context context, String k, String v) {
		PreferenceHelper.write(context, sp_path, k, v);
	}
	
	public static void write(Context context, String k, long v) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		preference.edit().putLong(k, v).commit();
	}

	public static int readInt(Context context, String k) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		return preference.getInt(k, 0);
	}

	public static int readInt(Context context, String k, int defv) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		return preference.getInt(k, defv);
	}
	
	public static long readLong(Context context, String k) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		return preference.getLong(k, 0l);
	}

	public static long readLong(Context context, String k, long defv) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		return preference.getLong(k, defv);
	}
	
	public static float readFloat(Context context, String k) {
		return readFloat(context, k, 0f);
	}

	public static float readFloat(Context context, String k, float defv) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		return preference.getFloat(k, defv);
	}

	public static boolean readBoolean(Context context, String k) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		return preference.getBoolean(k, false);
	}

	public static boolean readBoolean(Context context, String k, boolean defBool) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		return preference.getBoolean(k, defBool);
	}

	public static String readString(Context context, String k) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		return preference.getString(k, null);
	}

	public static String readString(Context context, String k, String defV) {
		SharedPreferences preference = context.getSharedPreferences(sp_path,
				Context.MODE_PRIVATE);
		return preference.getString(k, defV);
	}

	public static void remove(Context context, String k) {
		PreferenceHelper.remove(context, sp_path, k);
	}

	public static void clean(Context cxt) {
		PreferenceHelper.clean(cxt, sp_path);
	}
}
